<template>
  <div class="my_body">
    <div class="content">
      <div>
        <div class="login">
          <div class="title"><img style="height: 200px; width: 200px" src="../assets/img/juan.jpg"><br>校友捐赠系统登录</div>
          <div class="line">
            <img class="smallImg" src="../assets/img/2.png"/>
            <input placeholder="请输入账号" type="text" v-model="login"/>
          </div>
          <div class="line">
            <img class="smallImg" src="../assets/img/3.png"/>
            <input placeholder="请输入密码" type="password" v-model="password"/>
          </div>
          <button class="logBut" @click = "log">登&nbsp;&nbsp;录</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "login",
    data(){
      return{
        login :"",
        password : ""
      }
    },
    methods:{
      log(){
        console.log(11111111)
        let _this = this
        this.$post({
          url :  "login",
          data :{
            login : _this.login,
            password: _this.password
          }
        }).then(res=>{
          if(res.code !=0){
            alert("用户名或者密码错误！")
            this.login = this.password = ""
          }
          else{
            let data = res.data
            this.$store.commit("setPower",data.power)
            if(data.power == 1){
              this.$store.commit("setCollegeId",data.college.id)
            }
            this.$store.commit("setToken",data.token)
            this.$router.push({
              path : "view"
            })
          }
        }).catch(err =>{

        })
      }
    },
    mounted() {
      document.body.setAttribute("class","loginbody");
    },
    beforeDestroy(){
      document.body.removeAttribute("class","loginbody");
    }
  }
</script>

<style>
  .loginbody {
    background-image: url('../assets/img/back.jpg');
    text-align: center;
    background-size: 100% 100%;
    height: 100%;
    overflow: hidden;
    background-repeat: no-repeat;
    background-position: center;
    background-attachment: fixed;
  }

  .login {
    background: #fff;
    width: 21%;
    text-align: center;
    padding: 70px 2%;
    border-radius: 2px;
    position: absolute;
    top: 5%;
    right: 5%;
  }

  .title {
    font-weight: 600;
    font-size: 22px;
    color: #333;
    margin-bottom: 40px;
  }

  .line {
    border-bottom: 1px solid #d8d8d8;
    margin: 22px 1%;
    width: 96%;
  }

  .line input {
    border: none;
    padding: 0px 1%;
    margin: 1%;
    background: #fff;
    width: 84%;
    font-size: 16px;
    line-height: 30px;
    outline: none;
  }

  .line .smallImg {
    width: 26px;
    float: left;
    vertical-align: middle;
    margin-top: 1px;
  }

  .logBut {
    background: #0288df;
    padding: 10px 80px;
    border: none;
    color: #fff;
    margin-top: 40px;
    font-size: 16px;
    cursor: pointer;
  }
</style>
